package com.lzc.lblog.lblog.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.lzc.lblog.lblog.entity.MComment;
import com.lzc.lblog.lblog.mapper.MCommentMapper;
import com.lzc.lblog.lblog.service.MCommentService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.lzc.lblog.lblog.vo.CommentVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author lzczzzz
 * @since 2020-12-02
 */
@Service
public class MCommentServiceImpl extends ServiceImpl<MCommentMapper, MComment> implements MCommentService {
    @Autowired
    private MCommentMapper mCommentMapper;

    /**
     * 获取博客评论
     * @param page 分页信息
     * @param id 博客id
     * @param userId 用户id
     * @param created 排序
     * @return
     */
    @Override
    public IPage<CommentVo> selectListByPid(Page page, Long id, Long userId, String created) {
        return mCommentMapper.selectListByPid(page,new QueryWrapper<MComment>()
        .eq(id!=null,"post_id",id)
        .eq(userId!=null,"user_id",userId)
        .orderByDesc(created!=null,created));
    }
}
